<%--
Created by IntelliJ IDEA.
User: CY
Date: 2018/1/4
Time: 10:51
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html>
<head>
    <title>组织机构管理</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8 ? MYOA_CHARSET : htmlspecialchars($HTML_PAGE_CHARSET))?>" />
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <%--<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">--%>
    <meta name="viewport" content="width=device-width, initial-scale=0.3, user-scalable=0, minimum-scale=0, maximum-scale=5.0,user-scalable=yes">
    <link rel="stylesheet" href="/css/officialDocument/officialDocument.css">
    <link rel="stylesheet" href="/lib/pagination/style/pagination.css">
    <link rel="stylesheet" type="text/css" href="../css/sys/userManagement.css"/>
    <link rel="stylesheet" href="/lib/laydate/need/laydate.css">
    <link rel="stylesheet" href="/lib/layer/skin/default/layer.css">
<%--    <link rel="stylesheet" type="text/css" href="/css/street/street.css"/>--%>
    <link rel="stylesheet" type="text/css" href="/lib/layui/layui/css/layui.css"/>
    <%--<link rel="stylesheet" type="text/css" href="/css/patrol/patrol.css"/>--%>
    <link rel="stylesheet" href="../css/base.css">
    <script src="../js/jquery/jquery-1.9.1.js" type="text/javascript" charset="utf-8"></script>
    <script src="/js/base/base.js" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/layer/layer.js?20201106" type="text/javascript" charset="utf-8"></script>
    <script src="../lib/pagination/js/jquery.pagination.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="/js/base/tablePage.js"></script>
    <script src="/lib/laydate/laydate.js"></script>
    <script src="/lib/jquery.form.min.js"></script>
    <style>
        .content .left .collect .liUp:first-of-type{
            border-top:none!important;
        }
        body{
            margin:0px;
            overflow: hidden;
        }
        .info{
            width:180px;
            height:28px;
            border-radius: 3px;
            margin-left:20px;
            vertical-align: middle;
        }
        button{
            background: #2f8ae3;
            margin-left: 10px;
            padding: 5px 10px;
            border-radius: 4px;
            color: #fff;
            cursor: pointer;
            font-size:14px;
        }
        .content .left{
            /*overflow-x:auto;*/
        }
        #downChild .dpetWhole0 .childdept{
            padding-left: 60px!important;
        }
        #downChild .dpetWhole0 ul .childdept{
            padding-left: 80px!important;
        }
        #downChild .dpetWhole0 ul ul li .childdept{
            padding-left: 95px!important;
        }
        .content .right {
            margin-top: 0px;
        }
        #add{
            float:right;
            margin:0px 20px 0px 0px;
        }
        .table{
            width:96%;
            margin:5px auto 0px;
        }
        .tableFoot{
            margin-top:20px;
        }
        .childCheck{
            width:16px;
            vertical-align: middle;
        }
        #checkAll{
            margin-left:10px;
        }
        #outport{
            background: #cc0000;
        }
        #inportEdit{
            background: #009900;
        }
        .M-box3 .active{
            margin: 0px 3px;
            width: 29px;
            height: 29px;
            line-height: 29px;
            background: #2b7fe0;
            font-size: 12px;
            border: 1px solid #2b7fe0;
            color:#fff;
            text-align:center;
            display: inline-block;
        }
        .M-box3 a{
            margin: 0 3px;
            width: 29px;
            height: 29px;
            line-height: 29px;
            font-size: 12px;
            display: inline-block;
            text-align:center;
            background: #fff;
            border: 1px solid #ebebeb;
            color: #bdbdbd;
            text-decoration: none;
        }
        .mainBg .mainTitle{
            min-width: 750px;
        }
        .mainTitleUl .bordercolor span{
            font-size:14px;
        }
        .mainTitleUl .bordercolor label input[type=text]{
            font-size:14px;
        }
        .mainBg{
            padding-top:0px;
        }
        #houseProperty{
            background: none!important;
        }
        .allCheck div{
            height:25px;
            line-height:25px;
        }
        .mainTitleUl .bordercolor label .picture ul{
            height: 78px;
        }
        .mainTitleUl .bordercolor span{
            position: initial!important;
        }
        .clearfix{
            margin-left: 30px;
            margin-bottom: 10px;
        }
      /*  li span{
            width: 80px;
            display: inline- block;
        }
        li input{
            height: 30px;
            text-indent: 5px;
            border-radius:5px
        }
        li textarea{
            text-indent: 8px;
            width: 30%;
            height: 50px;
            border-radius:5px
        }*/
    </style>
  <%--  <link rel="stylesheet" href="/css/biaodan.css">--%>
</head>
<body>
<div class="headTop">
    <div class="headImg">
        <img src="/img/document/icon_agentDispatch.png" alt="">
    </div>
    <div class="divTitle">
        组织机构管理
    </div>
</div>
<div class="content" style="padding-top:55px;">
   <div class="left">
         <div class="cont_left" id="cont_left" style="    white-space: nowrap;width:100%">
            <ul>
                <li class="liDown dept_li" id="dept_lis"><img src="../img/sys/icon_sectorList.png" style="vertical-align: middle;width: 15px;margin-right: 10px;" alt="组织列表">组织结构</li>
                <li class="pick" style="display: block;">
                    <div class="pickCompany"><span style="height:35px;line-height:35px;" class="childdept"><img src="/img/spirit/icon_company.png" alt="" style="vertical-align: middle;width: 15px;margin-right: 10px;margin-left: 13px;margin-bottom: 4px;"><a id="indexHome" href="javascript:void(0)" class="dynatree-title" title=""></a></span></div>
                </li>
            </ul>
        </div>
    </div>
    <div class="right" style="display: block">
    <div class="tableList" >
        <div class="headNav">
            <%--<input type="text" class="info" placeholder="居委会名称">--%>
            <%--<button id="query">查询</button>--%>
            <%--<button id="inport">导入</button>--%>
            <%--<button id="inportEdit">导入修改</button>--%>
            <button class="choose" id="addl" data-type="0" style="margin-bottom: 4px;margin-right: 2.5%;float: right">新建</button>
        </div>
        <div class="table">
            <table>
                <thead>
                <tr>
                    <%--<th style="width:1%"></th>--%>
                    <th>组织排序号</th>
                    <th>党组织名称</th>
                    <th>坐标</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody class="list">

                </tbody>
            </table>
            <%--<div class="tableFoot">--%>
            <%--<input type="checkbox" id="checkAll"  style="width:16px;vertical-align: middle">--%>
            <%--<label for="checkAll" style="font-size:14px;">全选</label>--%>
            <%--<button id="outport">导出</button>--%>
            <%--</div>--%>
            <div style="margin: 0px auto 0px;height:50px;width: 97%;" class="clearfix">
                <div id="dbgz_page" class="M-box3" style="display: none">

                </div>
            </div>
        </div>
    </div>
    </div>
    <div class="mainBg" style="background: #fff;display: none">
        <iframe id="acifram" frameborder="0" scrolling="yes" height="100%" width="100%" onresize="noresize" src=""></iframe>
<%--        <form action="" id="datasave">--%>
<%--            <input type="file"  onchange="filesTwo(this)" multiple="multiple" name="file"--%>
<%--                   style="display: none"/>--%>
<%--            &lt;%&ndash;<input type="hidden" name="userId">&ndash;%&gt;--%>
<%--            &lt;%&ndash;<input type="hidden" name="checkId">&ndash;%&gt;--%>
<%--            <div class="mainTitle">--%>
<%--                <ul class="mainTitleUl">--%>
<%--                    <li class="bordercolor clearfix" style="margin-top: 20px">--%>
<%--                        <span style=""><b style="color: red;">*</b>党支部</span>--%>
<%--                        <label style="width: 80%;">--%>
<%--                            <select  name="partyBranch" id="dang" style="width:30%;font-size:14px;background: none"></select>--%>
<%--                        </label>--%>
<%--                    </li>--%>
<%--                </ul>--%>
<%--                <div style="height: 88px;line-height: 88px;text-align: center">--%>
<%--                    <a href="javascript:void (0)" class="preservation" style="margin-top: 25px;display: inline-block;margin-right: 10px;line-height: 1;font-size:18px;padding: 8px 20px;background: #2F8AE3;color: #fff;border-radius: 6px">保存</a>--%>
<%--                    <a href="javascript:void (0)" class="getBack"  style="margin-top: 25px;display: inline-block;line-height: 1;font-size:18px;padding: 8px 20px;background: #2F8AE3;color: #fff;border-radius: 6px">返回</a>--%>
<%--                </div>--%>
<%--            </div>--%>
<%--        </form>--%>
    </div>
</div>
<script>
    $('#indexHome').click(function(){
        window.location.reload();
    })
    $(document).on('click','.choose',function(){
        var type=$(this).attr('data-type');
       /* $('.tableList').hide();
        $('.mainBg').show();
        $('#dang').val('');*/
        if(type==0){//新建
            /*$('.preservation').attr('data-type','0');
            $('.dzb').hide();
            $('.kpxz').hide();*/
            // use();
            // refresh()
            // $('.addPhotos').show();
            window.open('/street/orangesnew?isEdit=false')
            //$('#acifram').attr('src','/street/orangesnew?isEdit=false')
        }else if(type==1){//查看
            var id=$(this).parents('tr').attr('id')
            $('.preservation').hide();
            $('.addPhotos').hide();
            $('.dzb').show();
            $('.kpxz').show();
            detail(id,type)
        }else{//修改
            var id=$(this).parents('tr').attr('id')
            /*$('.choose').attr('data-type','2');
            $('.choose').attr('data-id',id);
            $('.dzb').hide();
            $('.kpxz').hide();
            $('.addPhotos').show();*/
            //$('#datasave').attr('action','/integralManger/updateData?imid='+id)
            window.open('/street/orangesnew?orgDeptId='+id)
            // detail(id,type)
        }
    })
    function showDept(reg) {
        var data=reg.obj;
        //console.log(data);
        var str="";
        for(var i=0;i<data.length;i++){
            // var imgL=data[i].attachmentList;
            // var img=""
            // for(var h=0;h<imgL.length;h++){
            //     img +=   '<img src="/xs?'+imgL[h].attUrl+'" alt="" onclick="javascript:window.open(this.src)" style="width: 40px;height: 40px;margin-right: 10px;">'
            // }
            str+='  <tr id="'+data[i].orgDeptId+'">' +
                //                            '                    <td>' +
                //                            '                        <input type="checkbox" class="childCheck">' +
                //                            '                    </td>' +
                '                    <td>'+data[i].orgDeptNo+'</td>' +
                '                    <td><a href="javascript:;" class="choose" data-type="1">'+function(){
                    if(data[i].orgDeptName==undefined){
                        return ''
                    }else{
                        return data[i].orgDeptName;
                    }
                }()+'</a></td>' +
                // '                    <td><a href="javascript:;" class="choose" data-type="1">'+datas[i].activitySubject+'</a></td>' +
                '                    <td>'+data[i].gridLocation+'</td>' +
                // '                    <td>'+datas[i].assessmentTeamaudit+'</td>' +
                // '                    <td>'+datas[i].score+'</td>' +
                '                    <td>' +
                /* '                        <a href="javascript:;" class="choose" data-type="1">查看</a>' +*/
                '                        <a href="javascript:;" class="choose" data-type="2">修改</a>' +
                '                        <a href="javascript:;" class="del">删除</a>' +
                '                    </td>' +
                '                </tr>'
        }
        $('.list').html(str);
        if(reg.total>10){
            $('#dbgz_page').show();
            me.pageTwo(reg.total,me.data.pageSize,me.data.page)
        } else {
            $('#dbgz_page').hide();
        }
    }

    // $.ajax({
    //     type: 'get',
    //     url: '/orgDepartment/getPartyList',
    //     success: function (res) {
    //         console.log(res)
    //     }
    // });
    //    分页列表
    var ajaxPageLe={
        data:{
            page:1,//当前处于第几页
            pageSize:10,//一页显示几条
            useFlag:true
            // computationNumber:null
        },
        page:function () {
            var me=this;
            $.ajax({
                url:'/orgDepartment/getPartyList',
                type:'get',
                data:me.data,
                dataType:'json',
                success:function(reg){
                    var data=reg.obj;
                    //console.log(data);
                    var str="";
                    for(var i=0;i<data.length;i++){
                        // var imgL=data[i].attachmentList;
                        // var img=""
                        // for(var h=0;h<imgL.length;h++){
                        //     img +=   '<img src="/xs?'+imgL[h].attUrl+'" alt="" onclick="javascript:window.open(this.src)" style="width: 40px;height: 40px;margin-right: 10px;">'
                        // }
                        str+='  <tr id="'+data[i].orgDeptId+'">' +
                            //                            '                    <td>' +
                            //                            '                        <input type="checkbox" class="childCheck">' +
                            //                            '                    </td>' +
                            '                    <td>'+data[i].orgDeptNo+'</td>' +
                            '                    <td><a href="javascript:;" class="choose" data-type="1">'+function(){
                                if(data[i].orgDeptName==undefined){
                                    return ''
                                }else{
                                    return data[i].orgDeptName;
                                }
                            }()+'</a></td>' +
                            // '                    <td><a href="javascript:;" class="choose" data-type="1">'+datas[i].activitySubject+'</a></td>' +
                            '                    <td>'+data[i].gridLocation+'</td>' +
                            // '                    <td>'+datas[i].assessmentTeamaudit+'</td>' +
                            // '                    <td>'+datas[i].score+'</td>' +
                            '                    <td>' +
                            /* '                        <a href="javascript:;" class="choose" data-type="1">查看</a>' +*/
                            '                        <a href="javascript:;" class="choose" data-type="2">修改</a>' +
                            '                        <a href="javascript:;" class="del">删除</a>' +
                            '                    </td>' +
                            '                </tr>'
                    }
                    $('.list').html(str);
                    if(reg.total>10){
                        $('#dbgz_page').show();
                        me.pageTwo(reg.total,me.data.pageSize,me.data.page)
                    } else {
                        $('#dbgz_page').hide();
                    }
                }
            })

        },
        pageTwo:function (totalData, pageSize,indexs) {
            var mes=this;
            $('#dbgz_page').pagination({
                totalData: totalData,
                showData: pageSize,
                jump: true,
                coping: true,
                homePage:'',
                endPage: '',
                current:indexs||1,
                callback: function (index) {
                    mes.data.page=index.getCurrent();
                    mes.page();
                }
            });
        }
    }
    ajaxPageLe.page();

    //    点击删除
    $('.list').on('click','.del',function(){
        var id=$(this).parents('tr').attr('id')
        layer.confirm(' 确定要删除吗', {
            btn: ['确定', '取消'], //按钮
            title: " 删除"
        },function(){
            $.ajax({
                url:'/orgDepartment/delDepById',
                type:'post',
                dataType:'json',
                data:{deptId:id},
                success:function(res){
                    debugger
                    if(res.flag){
                        layer.msg(' 删除成功', {icon: 6});
                        ajaxPageLe.page();
                        window.location.reload();
                    }else{
                        layer.msg(res.msg)
                    }

                }
            })
        }, function () {
            layer.closeAll();
        })
    })

    //    查看详情
    function  detail(id,dataType) {
        $.ajax({
            url:'/orgDepartment/getPartyDeptById',
            dataType:'json',
            type:'get',
            success:function(res){
                var data=res.data;
//                 $('#dang').val(data.partyBranch);//居委会名称
//                 $('input[name="partyMember"]').val(data.partyMember)//房屋住址
// //
//                 $('input[name="activitySubject"]').val(data.activitySubject);//所有者姓名
//                 $('#activityContent').val(data.activityContent);//所有者身份证号
// //                $('input[name="phonenumber"]').val(data.phonenumber);//房屋面积
//
//
//                 //                    图片显示
//                 var obj=data.attachmentList;
//                 var str1=""
//                 for(var i=0;i<obj.length;i++){
//                     str1+='<li class="pic" style="padding-left: 10px;">' +
//                         '<img src="/xs?'+obj[i].attUrl+'" alt=""  style="cursor:pointer">' +function(){
//                             if(dataType==1){
//                                 return ''
//                             }else{
//                                 return '<b class="deleClear">x</b>';
//                             }
//                         }()+
//                         '<input type="hidden" class="hiddenId"  value="'+obj[i].aid+'@'+obj[i].ym+'_'+obj[i].attachId+'">' +//id
//                         '<input type="hidden"  class="hiddenName" value="'+obj[i].attachName+'">' +//名字
//                         '</li>'
//                 }
//                 $('.prevTwo>ul').html(str1);
//                 $('input[name="attachmentId"]').val(data.attachmentId)
//                 $('input[name="attachmentName"]').val(data.attachmentName)
//
//                 var arr=[];
//                 arr=data.scoreStandard.split(',');
//                 var arr1=arr.pop();
//                 var first=arr.shift();
//
//                 $('#jifen').val(first);
//                 var type=$('#jifen option:selected').attr('type');
//                 if(type!=undefined){
//                     $('.mainTitleUl .bordercolor .heiLabel').css('height','260px');
//                     $('.mainTitleUl .bordercolor .hei').css('height','260px');
//                     $('.mainTitleUl .bordercolor .hei').css('line-height','260px')
//
//                 }else if(type==undefined){
//                     $('.mainTitleUl .bordercolor .heiLabel').css('height','57px');
//                     $('.mainTitleUl .bordercolor .hei').css('height','57px');
//                     $('.mainTitleUl .bordercolor .hei').css('line-height','57px')
//                 }
// //                显示积分标准
//                 if(type!=undefined){
//                     $.get('/code/getCode?parentNo=JFZB_TYPE'+type ,function (json) {
//                         if(json.flag){
//                             var str='';
//                             for(var i=0;i<json.obj.length;i++){
//                                 str += '<div style="font-size:14px;text-align: left;margin-left:4%;"><input type="checkbox" style="float:none;width:16px;" class="check" value="'+json.obj[i].codeNo+'">'+json.obj[i].codeName+'</div>'
//                             }
//                             $('.allcheck').html(str)
//                             for(var i=0;i<arr.length;i++){
//                                 $('.check').each(function(){
//                                     if($(this).val()==arr[i]){
//                                         $(this).prop('checked',true)
//                                     }
//                                 })
//                             }
//
//                         }
//                     })
//                 }else{
//                     $('.allcheck').html('')
//                 }
//                 $('input[name="scoreOld"]').val(data.scoreOld)
//                 $('input[name="score"]').val(data.score)
//                 check('partyBranchaudit',data.partyBranchaudit)
//                 check('assessmentTeamaudit',data.assessmentTeamaudit)

            }
        })
    }
    //左侧方法
    var loadSidebarUrl='';
    loadSidebarUrl="/orgDepartment/queryByDepIdList"
    boolTwo=false;
    numstring=true;
    $('.left').height($(document).height()-46)
    var userstr;
    var user_id;
    var numdept;
    $("#dept_lis").on('click', function () {

        if ($(this).siblings('.pick').css('display') == 'none') {
            $(this).siblings('.pick').show();
            $(this).addClass("liDown").removeClass("liUp");
        } else {
            $(this).siblings('.pick').hide();
            $(this).addClass("liUp").removeClass("liDown");
        }
    });
    function imgDownOrg(deptNum, me) {
        ajaxdata(deptNum, me);
        if ($(me).attr('data-types') == undefined) {
            $(me).find('img').attr('src', $(me).find('img').attr('src') == '/img/sys/dapt_right.png' ? '/img/sys/dapt_down.png' : '/img/sys/dapt_right.png');
            if ($(me).find('img').attr('src') == '/img/sys/dapt_right.png') {
                $(me).find('img').css({"margin-top": "-3px", "margin-right": "4px", "margin-left": ""});
                $(me).find('img').width(8);
                $(me).find('img').height(14);
                $(me).next().hide();
                // $(me).next().html('')
            } else if ($(me).find('img').attr('src') == '/img/sys/dapt_down.png') {
                $(me).find('img').css({"margin-top": "-3px", "margin-right": "4px", "margin-left": "-5px"});
                $(me).find('img').width(14);
                $(me).find('img').height(9);
                $(me).next().show();
            }
        }
        else {
            $(me).find('img').attr('src', $(me).find('img').attr('src') == '/img/sys/dapt_right.png' ? '/img/sys/dapt_down.png' : '/img/sys/dapt_right.png');
            if ($(me).find('img').attr('src') == '/img/sys/dapt_right.png') {
                $(me).find('img').width(8);
                $(me).find('img').height(14);
            } else if ($(me).find('img').attr('src') == '/img/sys/dapt_down.png') {
                $(me).find('img').width(14);
                $(me).find('img').height(9);
            }
            if ($(me).attr('data-types') == '1') {
                $(me).next().show();
                $(me).attr('data-types', '2')
            } else if ($(me).attr('data-types') == '2') {
                $(me).next().hide();
                $(me).attr('data-types', '1')
            }
        }

        $('#btn').attr('data_id',deptNum);

        if ($(me).attr('data-numstring') == 1) {
            if (boolTwo) {
                if ($(me).next().css('display') == 'none') {
                    return;
                }
                $.loadrole($(me).next(), deptNum, $(me).attr('data-numtrue'));
            } else {
                loadSidebarOrg($(me).next(), deptNum)
            }
        }
        if($(me).next().html()=='') {
            if (boolTwo) {
                $.loadrole($(me).next(), deptNum, $(me).attr('data-numtrue'), function () {
                    if (departments) {
                        $.loadSidebar($(me).next(), deptNum)
                    }
                })
            }
        }
        if ($(me).attr('data-numstring') == 2) {
            if (numstring) {
                $.loadSidebar($(me).next(), deptNum)
            }
        }
    }
    function loadSidebarOrg(target, deptId, fn) {
        $.ajax({
            url: '/orgDepartment/getChDept',
            type: 'get',
            data: {
                deptId: deptId
            },
            dataType: 'json',
            success: function (data) {
                showDept(data);
                if (deptId == 0) {
                    var str = '';
                    if ($(target).children('li').length == 0) {
                        data.obj.forEach(function (v, i) {
                            if (v.orgDeptName) {
                                str += '<li><span data-types="1" data-numstring="1"   data-numtrue="1" ' +
                                    'onclick= "imgDownOrg(' + v.orgDeptId + ',this)"  ' +
                                    'style="height:35px;line-height:35px;padding-left: 14px" ' +
                                    'deptid="' + v.orgDeptId + '" class="childdept"><span class="">' +
                                    '</span><img src="/img/commonTheme/${sessionScope.InterfaceModel}/icon_company.png" alt="" ' +
                                    'style="vertical-align: middle;width: 15px;' +
                                    'margin-right: 10px;margin-left:15px;">' +
                                    '<a href="javascript:void(0)" ' +
                                    'class="dynatree-title" title="' + v.orgDeptName + '">' + v.orgDeptName + '</a>' +
                                    '</span><ul style="display:none;" class="dpetWhole0"></ul></li>';
                            }
                        })
                        target.html(str);
                    } else {
                        $(target).children('li').each(function (v, l) {
                            for (var i = 0; i < data.obj.length; i++) {
                                if ($($(target).children('li')[i]).children('span').attr('deptid') != data.obj[i].deptId) {
                                    if (v.orgDeptName) {
                                        str = '<li><span data-types="1" data-numstring="1"   data-numtrue="1" ' +
                                            'onclick= "imgDownOrg(' + data.obj.orgDeptId + ',this)"  ' +
                                            'style="height:35px;line-height:35px;padding-left: 14px" ' +
                                            'deptid="' + data.obj.orgDeptId + '" class="childdept">' +
                                            '<span class="">' +
                                            '</span><img src="/img/commonTheme/${sessionScope.InterfaceModel}/icon_company.png" alt="" ' +
                                            'style="vertical-align: middle;width: 15px;' +
                                            'margin-right: 10px;margin-left:15px;">' +
                                            '<a href="javascript:void(0)" ' +
                                            'class="dynatree-title" title="' + data.obj.orgDeptName + '">' + data.obj.orgDeptName + '</a>' +
                                            '</span><ul style="display:none;" class="dpetWhole0"></ul></li>';
                                    }
                                    $(target).append(str)
                                }
                            }
                            return false
                        })
                    }
                    widthnum++;
                    if (fn != undefined) {
                        fn($(target).find('.dpetWhole0'))
                    }
                } else {
                    var str = '';
                    if ($(target).children('li').length == 0) {
                        data.obj.forEach(function (v, i) {
                            var targetnum = parseInt($(target).prev().attr('data-numtrue'))

                            if (v.orgDeptName && v.isHaveCh == 1) {
                                str += '<li><span  onclick= "imgDownOrg(' + v.orgDeptId + ',this)" ' +
                                    'data-numString="2" deptid="' + v.orgDeptId + '" ' +
                                    'data-numtrue="' + (targetnum + 1) + '"  ' +
                                    'style="padding-left:' +
                                    (20 + (20 * parseInt($(target).prev().attr('data-numtrue')))) + 'px;' +
                                    'height:35px;line-height:35px;"  deptid="' + v.orgDeptId + '" class="childdept">' +
                                    '<span></span><img id="img' + v.orgDeptId + '" src="/img/sys/dapt_right.png" ' +
                                    'style="width: 8px;height:14px;margin-top: -3px;margin-right:4px;" alt="">' +
                                    '&nbsp;<a href="javascript:void(0)" class="dynatree-title" ' +
                                    'title="' + v.orgDeptName + '">' + v.orgDeptName + '</a></span>' +
                                    '<ul style="display:none;"></ul></li>';
                            } else {
                                str += '<li>' +
                                    '<span onclick="imgDownOrg(' + v.orgDeptId + ',this)" ' +
                                    'data-numString="1" deptid="' + v.orgDeptId + '" ' +
                                    'data-numtrue="' + (targetnum + 1) + '" ' +
                                    'style="padding-left:' + (20 + (20 *
                                        parseInt($(target).prev().attr('data-numtrue')))) + 'px;' +
                                    'height:35px;line-height:35px;"  deptid="' + v.orgDeptId + '" ' +
                                    'class="childdept"><span></span><img  src="/img/sys/dapt_right.png" ' +
                                    'style="width: 8px;height:14px;margin-top: -3px;margin-right:4px;" ' +
                                    'alt="">&nbsp;<a href="javascript:void(0)" class="dynatree-title" ' +
                                    'title="' + v.orgDeptName + '">' + v.orgDeptName + '</a></span><ul ' +
                                    'style="display:none;"></ul></li>';
                            }

                        });
                        target.html(str);
                    } else {
                        $(target).children('li').each(function (v, l) {

                            for (var i = 0; i < data.obj.length; i++) {



                                if ($($(target).children('li')[i]).children('span').attr('deptid') != data.obj[i].orgDeptId) {

                                    var targetnum = parseInt($(target).prev().attr('data-numtrue'))

                                    if (data.obj[i].orgDeptName && data.obj[i].isHaveCh == 1) {
                                        str = '<li><span  onclick= "imgDownOrg(' + data.obj[i].orgDeptId + ',this)" ' +
                                            'data-numString="2" deptid="' + data.obj[i].orgDeptId + '" ' +
                                            'data-numtrue="' + (targetnum + 1) + '"  ' +
                                            'style="padding-left:' +
                                            (20 + (20 * parseInt($(target).prev().attr('data-numtrue')))) + 'px;' +
                                            'height:35px;line-height:35px;"  deptid="' + data.obj[i].orgDeptId + '" class="childdept">' +
                                            '<span></span><img id="img' + data.obj[i].orgDeptId + '" src="/img/sys/dapt_right.png" ' +
                                            'style="width: 8px;height:14px;margin-top: -3px;margin-right:4px;" alt="">' +
                                            '&nbsp;<a href="javascript:void(0)" class="dynatree-title" ' +
                                            'title="' + data.obj[i].orgDeptName + '">' + data.obj[i].orgDeptName + '</a></span>' +
                                            '<ul style="display:none;"></ul></li>';
                                    } else {
                                        str = '<li>' +
                                            '<span onclick="imgDownOrg(' + data.obj[i].orgDeptId + ',this)" ' +
                                            'data-numString="1" deptid="' + data.obj[i].orgDeptId + '" ' +
                                            'data-numtrue="' + (targetnum + 1) + '" ' +
                                            'style="padding-left:' + (20 + (20 *
                                                parseInt($(target).prev().attr('data-numtrue')))) + 'px;' +
                                            'height:35px;line-height:35px;"  deptid="' + data.obj[i].orgDeptId + '" ' +
                                            'class="childdept"><span></span><img  src="/img/sys/dapt_right.png" ' +
                                            'style="width: 8px;height:14px;margin-top: -3px;margin-right:4px;" ' +
                                            'alt="">&nbsp;<a href="javascript:void(0)" class="dynatree-title" ' +
                                            'title="' + data.obj[i].deptName + '">' + data.obj[i].deptName + '</a></span><ul ' +
                                            'style="display:none;"></ul></li>';
                                    }
                                    $(target).append(str)
                                }
                            }
                            return false;
                        })
                    }
                    widthnum++
                    if (fn != undefined) {
                        fn();
                    }
                }
            }
        })
    }
    function ajaxdata (depeId,me) {
        $('.newroletwo').children('span').text($(me).children('a').text());
        $('.newroletwo').children('input').val($(me).attr('deptid'));
        /*deptById({'orgDeptId':depeId},$('.list'))*/
        $('#btn').attr('dataType',depeId)
    }
    $(function () {
        var boolTwo= false;
//        组织左侧数据渲染
//        <img src="/img/spirit/icon_company.png">
        loadSidebar1($('.pick'),0)


        function loadSidebar1(target,deptId,fn) {
            $.ajax({
                url: '/orgDepartment/queryByDepIdList',
                type: 'get',
                data: {
                    deptId: deptId
                },
                dataType: 'json',
                success: function (data) {
                    var str = '';
                    data.obj.forEach(function (v, i) {
                        if (v.deptName) {
                            str += '<li><span  data-numtrue="1" ' +
                                'onclick= "imgDownOrg(' +v.deptId + ',this)" data-types="1"  data-numString="1"  style="height:35px;line-height:35px;padding-left: 14px" deptid="' + v.deptId + '" class="childdept"><span class=""></span><img src="/img/sys/dapt_right.png" alt="" style="margin-left: 12px;width: 8px;height: 14px;margin-top: -3px;margin-right: 4px;"><a href="javascript:void(0)" class="dynatree-title" title="' + v.deptName + '">' + v.deptName + '</a></span><ul style="display:none;" class="dpetWhole0"></ul></li>';
                        }
                    })
                    /*  widthnum++;*/
                    target.append(str);

                }
            })
        }
        $.ajax({
            url:'/sys/showUnitManage',
            type:'get',
            dataType:"JSON",
            data : '',
            success:function(obj){
                var data = obj.object.unitName;
                $('.pick .pickCompany .dynatree-title').text(data).attr('title',data);

            },
            error:function(e){
//                console.log(e);
            }
        })

        $('.rightMain ').height($(document).height()-46);

        $('#btn').click(function(){
            <%--userstr=$('.newroletwo').find('span').text();--%>
            <%--if(userstr==''){--%>
            <%--$.layerMsg({content:'<fmt:message code="sys.th.DepartmentFirst" />',icon:2});--%>
            <%--return--%>
            <%--}--%>
            numdept=$('.newroletwo').find('input').val();
            var id=$(this).attr('dataType');
            if(id == ""){
                $.layerMsg({content:'请选择所属党支部',icon:6})
            }else{
                window.open('/street/addParty?type='+id,'<fmt:message code="userManagement.th.NewUser" />');
            }

        });

        $('#allSelUser ').on('change',function () {

            var deptId= 0 ;
            var deptIdDom = $('.collect .add_back').attr('deptid');
            if(deptIdDom!=undefined&&deptIdDom!=''&&deptIdDom!='undefined'){
                deptId = deptIdDom;
            }
            var data={
                'deptId':deptId,
                'notLogin':$(this).val()
            };

            if($(this).val()==''){
                delete data.notLogin;
            }

            deptById(data,$('.tr_befor'))

        });

        /*init()*/
//        getChDept($('#ULDown'),30);
        $('.AUP').click(function(){
            //$('#ulList').slideToggle();
            if($('#downChild').css('display')=='block'){
                $(this).addClass('liUp').removeClass('liDown');
                $('#downChild').slideUp();
            }else{
                $(this).addClass('liDown').removeClass('liUp');
                $('#downChild').slideDown();
            }
        });
        $('.proceed').click(function () {
            $.layerMsg({content:'<fmt:message code="lang.th.Upcoming" />',icon:6})
        });

        $('.employee').click(function () {
            var data={
                'deptId':0,
                'notLogin':$('#allSelUser').val()
            };
            deptById(data,$('.tr_befor'));
        });

        // 查询新增用户
        $('.newUsers').click(function(){
            $('.tab').find('.userData').remove();
            $('.content .right').css("display","block");
            $('.content .rightMain').css("display","none");
            $.ajax({
                url:'../user/getNewUsers',
                type:'get',
                dataType:'json',
                success:function(rsp){
                    var data1=rsp.obj;
                    //console.log(data1);
                    var str='';
                    for(var i=0;i<data1.length;i++){
                        var colorNum='';
                        var lastVisitTime=''
                        if(data1[i].password=='') {
                            colorNum = 'colorRed'
                        }
                        if(data1[i].notLogin==1){
                            colorNum='colorddd'
                        }
                        if(data1[i].lastVisitTime!=undefined){
                            lastVisitTime=data1[i].lastVisitTime
                        }

                        str += '<tr class="userData '+colorNum+'" uId="' + data1[i].uid + '">' +
                            '<td><input type="checkbox" class="checkChild" name="checkbox" value="" style="width:13px;height:13px;" /></td>' +
                            '<td>' + data1[i].byname + '</td>' +
                            '<td>' + data1[i].userName + '</td>' +
                            '<td data-deptid="'+data1[i].deptId+'">' + data1[i].deptName + '</td>' +
                            '<td>' + function () {
                                switch (data1[i].dutyType) {
                                    case 1:
                                        return '<fmt:message code="sys.th.RegularClass" />';
                                        break
                                    case 2:
                                        return '<fmt:message code="sys.th.Whole-day" />';
                                        break
                                    case 99:
                                        return '<fmt:message code="sys.th.ShiftSystem" />';
                                        break
                                }

                            }() + '</td>' +
                            '<td>' + data1[i].userPrivName + '</td>' +
                            '<td>' +function () {
                                switch (parseInt(data1[i].postPriv)) {
                                    case 1:
                                        return '<fmt:message code="url.th.all" />';
                                        break
                                    case 2:
                                        return '<fmt:message code="sys.th.DesignatedDepartment" />';
                                        break
                                    case 0:
                                        return '<fmt:message code="sys.th.ThisDepartment" />';
                                        break
                                }

                            }()  + '</td>' +
                            '<td>' + lastVisitTime + '</td>' +
                            '<td>' + data1[i].idleTime + '</td>' +
                            '<td><a href="javascript:void(0)" onclick="clickrenwu('+data1[i].uid+',this)" style="margin-right: 5px;"><fmt:message code="global.lang.edit" /></a></td>' +
                            '</tr>';  //<a href="javascript:;">
                        <%--<fmt:message code="userManagement.th.MenuAauthority" />--%>
                        //</a>:菜单权限查看

                    }

                    $('.tr_befor').after(str);
                    $('.userData').click(function(){
                        var inCh=$(this).find('.checkChild').prop('checked');
                        if(inCh == true){
                            $(this).find('.checkChild').prop('checked',true);
                            $(this).addClass('bgColor');
                        }else{
                            $('#checkedAll').prop('checked',false);
                            $(this).find('.checkChild').prop('checked',false);
                            $(this).removeClass('bgColor');
                        }
                        var child = $(".checkChild");
                        for(var i=0;i<child.length;i++){
                            var childstate= $(child[i]).prop("checked");
                            if(inCh!=childstate){
                                return
                            }
                        }
                        $('#checkedAll').prop("checked",inCh);
                    })
                }
            })
        })
        // 查询和导出
        $('.queryExport').click(function () {
            $('.content .right').css("display","none");
            $('.rightMain').css("display","block");
            $('.rightMain iframe').attr("src","../user/goQueryExportUsers");
        });
        // 导入
        $('.import').click(function () {
            $('.content .right').css("display","none");
            $('.rightMain').css("display","block");
            $('.rightMain iframe').attr("src","../user/goImportUsers");
        });
        // 批量设置
        $('.editUserBatch').click(function () {
            $('.content .right').css("display","none");
            $('.rightMain').css("display","block");
            $('.rightMain iframe').attr("src","../user/goEditUserBatch");
        });

//        //部门人员情况列表
//        $('#ULDown').on('click','.childdept',function(){
//            var  that = $(this);
//            var deptid=that.attr('deptid');
//            var deName=that.attr('Name');
//            var val=$('#allSelUser option:checked').val();
//            $('.childdept').removeClass('on');
//            that.addClass('on')
//            getChDept(that.next(),deptid);
//            that.next().slideToggle();
//            var data={
//                'deptId':deptid,
//                'notLogin':val
//            }
//            $('.newDept').text('（'+deName+'）');
//            $('.currentDept').text('（'+deName+'）');
//            deptById(data,$('.tr_befor'));
//        })

        //全选点击事件
        $('#checkedAll').click(function(){
            var state =$(this).prop("checked");
            if(state==true){
                $(this).prop("checked",true);
                $(".checkChild").prop("checked",true);
                $(".userData").addClass('bgcolor');
            }else{
                $(this).prop("checked",false);
                $(".checkChild").prop("checked",false);
                $('.userData').removeClass('bgcolor');
            }
        })

        //删除人员按钮
        $('.ONE').click(function(){
            if($('.tab table input[type="checkbox"]:checked').length==0){
                $.layerMsg({content:'<fmt:message code="sys.th.PleaseFirst" />',icon:1})
                return
            }
            buttonInterface('/OrgPartyMember/delete','<fmt:message code="sys.th.MakeSureDelete" />？');
        })
        //清空在线时长按钮
        $('.TWO').click(function(){
            if($('.tab table input[type="checkbox"]:checked').length==0){
                $.layerMsg({content:'<fmt:message code="sys.th.PleaseFirst" />',icon:1})
                return
            }
            buttonInterface('../user/clearOnLine','<fmt:message code="sys.th.MakeSureEmpty" />？');
        })
        //清空密码按钮
        $('.THREE').click(function(){
            if($('.tab table input[type="checkbox"]:checked').length==0){
                $.layerMsg({content:'<fmt:message code="sys.th.PleaseFirst" />',icon:1})
                return
            }
            buttonInterface('../user/clearPassword','<fmt:message code="sys.th.VerifyPassword" />？');
        })
        //禁止登录按钮
        $('.FOUR').click(function(){
            if($('.tab table input[type="checkbox"]:checked').length==0){
                $.layerMsg({content:'<fmt:message code="sys.th.PleaseFirst" />',icon:1})
                return
            }
            buttonInterface('../user/setNotLogin','<fmt:message code="sys.th.MakeSure" />？');
        })
        // 提醒空密码用户按钮
        $('.FIVE').click(function(){
            $.layerMsg({content:'<fmt:message code="lang.th.Upcoming" />',icon:1})
            return
        })
        // 批量修改部门按钮
        $('.SIX').click(function(){
            if($('.tab table input[type="checkbox"]:checked').length==0){
                $.layerMsg({content:'<fmt:message code="sys.th.PleaseFirst" />',icon:1})
                return
            }
            layer.open({
                title:'<fmt:message code="sys.th.BatchModification" />',
                content:'<div>' +
                    '<table>' +
                    '<tr><td style="border-right: 1px solid #ddd"><fmt:message code="main.usermanage" />:</td><td><textarea style="margin-right: 10px;" name="" id="textareaopen"></textarea><a href="javascript:void(0)" class="addopens"><fmt:message code="global.lang.add" /></a></td></tr>' +
                    '<tr><td style="border-right: 1px solid #ddd"><fmt:message code="sys.th.NewSector" />:</td><td><select style="width: 139px;margin-left: -28px;" name="" id="newselectrrole"></select></td></tr>' +
                    '<tr><td style="border-right: 1px solid #ddd"><fmt:message code="sys.th.ReminderDepartment" />:</td><td><label style="margin-right: 10px;"><input name="checktit" type="checkbox"><fmt:message code="notice.th.remindermessage" /></label>' +
                    '<label><input name="checktit" type="checkbox"><fmt:message code="sys.th.SendReminderMessage" /></label></td></tr></table></div>',
                area:['500px','300px'],
                btn:['<fmt:message code="global.lang.ok" />','<fmt:message code="depatement.th.quxiao" />'],
                yes:function (index) {

                    var obj={
                        'deptId':$('#newselectrrole').val(),
                        'uids':$('#textareaopen').attr('user_id')

                    }
                    $.post('/user/editUsersDeptId',obj,function (json) {
                        if(json.flag){
                            $.layerMsg({content:'<fmt:message code="sys.th.SwapComplete" />',icon:1},function () {
                                location.reload()
                            })
                        }
                    },'json')
                },
                success:function () {
                    $('#newselectrrole').deptSelect(function (me) {//me是传过来的this，newselectrrole
                        $('#newselectrrole').val($('.tab table tbody [type="checkbox"]:checked').parent().parent().find('td').eq(3).attr('data-deptid'))
                        $(me).append('<option value="0"><fmt:message code="userManagement.th.Outgoing" /></option>')
                    })
                    var strcheck='',struserId='';
                    $('.tab table tbody [type="checkbox"]:checked').each(function(){
                        strcheck+=$(this).parent().parent().find('td').eq(2).text()+',';
                        struserId+=$(this).parent().parent().find('td').eq(1).text()+',';
                    })
                    $('#textareaopen').val(strcheck)
                    $('#textareaopen').attr('user_id',struserId)
                    $('.addopens').click(function(){
                        user_id=$(this).prev().prop('id')
                        $.popWindow("../common/selectUser");
                    })
                }
            })

        });


        //    点击导入
        /* $('#inport').click(function(){
             layer.open({
                 type:1,
                 title: ['党员信息导入', 'background-color:#2b7fe0;color:#fff;'],
                 area: ['600px', '420px'],
                 btn: ['导入', '取消'],
                 content:'<div>' +
                 '<form class="form1" name="form1" id="uploadForm" method="post" action="/OrgPartyMember/ecoudInsert" enctype="multipart/form-data">' +
                 '<table class="importTable"> ' +
                 '<tr><td style="width: 100px;">下载导入模板：</td><td style="text-align: left;"><a id="model" style="cursor:pointer">党员信息模板下载</a></td></tr>' +
                 '<tr> <td>选择导入文件：</td> <td><input style="width: auto" type="file" name="file"/></td> </tr>' +
                 '<tr>' +
                 '<td>说明：</td>'+
                 '<td style="text-align: left;"><p>1、请导入.xls文件或者.xlsx。</p>'+
 //            '<p>2、请填写网格信息中已有网格。</p>'+
                 ' </td> ' +
                 '</tr>' +
                 '</table>' +
                 '</form>' +
                 '</div>',
                 success:function(){
                     $('#model').click(function () {
                         window.location.href = "/file/grid/gridInfo_import.xls";
                     });
                 },
                 yes:function(obj){
                     var flag = CheckForm();
                     if (flag) {
                         layer.msg("正在导入中，请耐心等候", {icon: 1});
                         $.upload($('#uploadForm'), function (res) {
                             if(res.flag) {
                                 layer.msg("导入成功", {icon: 1});
                             }else{
                                 layer.msg("导入失败", {icon: 2});
                             }
                         });

                         location.reload()
                     }
                 }
             })
         })*/
        function CheckForm(){
            if(document.form1.file.value==""){
                layer.msg("请导入至少一条数据！",{icon:2});
                return (false);
            }
            return (true);
        }

        function init(){
            $.ajax({
                url:'../orgDepartment/getChDept',
                type:'get',
                data:{'deptId':20 },
                dataType:'json',
                success:function(res){
                    var data1=res.obj;
                    var str='';
                    str='<span deptid="'+data1.deptId+'" class="childdept" style="display: block;width:100%;padding:8px 0 8px 30px;font-size: 14px;"><a href="javascript:void(0)" class="dynatree-title" title="'+data1[0].deptName+'">'+data1[0].deptName+'</a></span>'
                    $('#ULDown').before(str);
                }
            })
        }

        //部门人员树状图方法
        function getChDept(element,deptId){

            $.ajax({
                url:'../department/getChDept',
                type:'get',
                data:{'deptId':deptId },
                dataType:'json',
                success:function(data){

                    if(deptId==30){
                        var str = '';
                        data.obj.forEach(function(v,i){
                            if(v.deptName){
                                str+='<li><span deptid="'+v.deptId+'" Name="'+v.deptName+'" class="childdept"><img style="margin-left: 42px;margin-right: 5px" src="../img/main_img/company_logo.png" alt=""><a href="javascript:void(0)"  class="dynatree-title" title="'+v.deptName+'">'+v.deptName+'</a></span><ul></ul></li>';
                            }else{
                                str+='<li><span deptid="'+v.deptId+'" Name="'+v.deptName+'" class="childdept"><span><img style="margin-left: 65px;margin-right: 5px" src="../img/main_img/man.png" alt=""></span><img style="margin-left: 65px;margin-right: 5px" src="../img/main_img/man.png" alt=""><a href="javascript:void(0)"  class="dynatree-title" title="'+v.userName+'">'+v.userName+'</a></span><ul></ul></li>';
                            }
                        });
                    }else{
                        var str = '';
                        data.obj.forEach(function(v,i){
                            if(v.deptName){
                                str+='<li><span deptid="'+v.deptId+'" Name="'+v.deptName+'" class="childdept"><img style="margin-left: 65px;margin-right: 5px" src="../img/main_img/company_logo.png" alt=""><a href="javascript:void(0)" data-uid="'+v.uid+'" onclick="edituser(this)" class="dynatree-title" title="'+v.deptName+'">'+v.deptName+'</a></span><ul></ul></li>';
                            }else{
                                if(v.sex==0){
                                    str+='<li><span deptid="'+v.deptId+'" Name="'+v.deptName+'" class="childdept"><img style="margin-left: 65px;margin-right: 5px" src="../img/main_img/man.png" alt=""><a href="javascript:void(0)" data-uid="'+v.uid+'" onclick="edituser(this)" class="dynatree-title" title="'+v.userName+'">'+v.userName+'</a></span><ul></ul></li>';
                                }else if(v.sex==1){
                                    str+='<li><span deptid="'+v.deptId+'" Name="'+v.deptName+'" class="childdept"><img style="margin-left: 65px;margin-right: 5px" src="../img/main_img/women.png" alt=""><a href="javascript:void(0)" data-uid="'+v.uid+'" onclick="edituser(this)" class="dynatree-title" title="'+v.userName+'">'+v.userName+'</a></span><ul></ul></li>';
                                }
                            }

                        });
                    }
                    element.html(str);

                }
            })
        }

        //人员列表展示


        //列表功能按钮
        function buttonInterface(URL,txt){
            var deptid=$('#btn').attr('dataType');
            var val=$('#allSelUser option:checked').val();

            var string='';
            $('.tab table input[type="checkbox"]:checked').each(function(i,n){
                string+=$(this).parent().parent().attr('uId')+',';
            })
//           var str=string.split("").join(",");
            var msg=txt;

            $.layerConfirm({title:msg,content:msg,icon:0},function(){
                $.ajax({
                    type:'post',
                    url:URL,
                    dataType:'json',
                    data:{'opIds':string},
                    success:function(res){
//                        console.log(res.flag);
//                        deptById(data,$('.tr_befor'));
                        deptById({'deptId':deptid,'orgDeptId':$('#allSelUser').val()},$('.list'))
                        /*location.reload()*/
                    }
                })
            })

        }
    })
</script>
</body>
</html>
